#! /usr/bin/env node
const fs = require('fs');
const { statSync, existsSync, readFileSync, readdirSync } = require('fs');
const path = require('path');

// 读取文件夹
const rootpath = process.cwd();
// console.log(existsSync(rootpath))
if (existsSync(rootpath)) {
    if (statSync(rootpath).isDirectory()) {
        // 是个文件夹
        console.log(readdirSync(rootpath))
    }
}


// cat

// console.log(fs.readFileSync(path.join(process.cwd(),process.argv[2]),'utf-8'))

// if (fs.readdirSync(process.cwd())) {
//     let reads = fs.readdirSync(process.cwd())[2];
//     console.log(fs.readFileSync(reads, 'utf-8'))
// } else {
//     console.log('读取失败')
// }

const argvs = process.argv[2];
const pathdir = path.join(process.cwd(),argvs)
// console.log(argvs)
// console.log(readFileSync(pathdir,'utf-8'))

if(existsSync(pathdir)){
    if(statSync(pathdir).isDirectory()){
        console.log('是文件夹')
    }else{
        console.log(readFileSync(pathdir).toString())
    }
}else{
    console.log('不存在')
}

